//
//  XZHMovieDetailViewController.m
//  Piece
//
//  Created by dllo on 16/6/13.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "XZHMovieDetailViewController.h"
#import "ZHNetworkHandler.h"
#import "XZHMovieDetailModel.h"
#import "UIImageView+WebCache.h"
#import "DYJMovieScoreView.h"
#import "Masonry.h"
#import "XZHMovieStoryModel.h"
#import "XZHMovieStoryView.h"
#import "XZHMovieCommentTableViewCell.h"
#import "XZHMovieFormView.h"
#import "XZHMovieScaleView.h"
#import "XZHMovieCommentViewController.h"
#import "XZHMovieCommentModel.h"
#import "HDVideoPlayerController.h"
#import "TBCircularSlider.h"
#import "JZShareCustom.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import "UIImageView+WebCache.h"
#import "FeHourGlass.h"
#import "HDVideoPlayerView.h"
#import "AudioPlayerManager.h"
#import "HYBLoopScrollView.h"

@interface XZHMovieDetailViewController ()<UITableViewDelegate, UITableViewDataSource, HDVideoPlayerDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *commentDataSource;
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIView *footerView;

@property (nonatomic, strong) DYJMovieScoreView *scoreView;
@property (nonatomic, strong) XZHMovieStoryView *storyView;
@property (nonatomic, strong) XZHMovieFormView *formView;
@property (nonatomic, strong) XZHMovieScaleView *scaleView;
/** 轮播图视图 */
@property (nonatomic, strong) HYBLoopScrollView *cycleView;

@property (nonatomic ,strong) HDVideoPlayerController *videoPlayerController;
@property (nonatomic, strong) UIButton *scoreBtn;
@property (nonatomic, strong) UILabel *scoreLabel;
@property (nonatomic, strong) UIView *giveScoreView;
@property (nonatomic, strong) UILabel *rankLabel;

/** 加载动画 */
@property (strong, nonatomic) FeHourGlass *hourGlass;
@end

@implementation XZHMovieDetailViewController
{
    TBCircularSlider *_slider;
}
@synthesize videoPlayerController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTitle:@"电影详情"];
    [self setUpTableView];
    [self getMovieDetailDataByUrl];
    [self getMovieCommentDataByUrl];
    [self createGiveScoreView];
}

#pragma mark - 定时器
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [self.cycleView startTimer];
}


- (void)setUpTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 64) style:UITableViewStylePlain];
//    self.tableView.backgroundColor = [UIColor cyanColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    
    [self setUpTableViewHeaderView];
    
    [self setUpTableViewFooterView];
    

    [self.tableView registerNib:[UINib nibWithNibName:@"XZHMovieCommentTableViewCell" bundle:nil] forCellReuseIdentifier:@"commentCell"];
}


- (void)setUpTableViewHeaderView {
    self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 220)];
    self.tableView.tableHeaderView = _headerView;
    self.cycleView = [HYBLoopScrollView loopScrollViewWithFrame:CGRectMake(0, 0, ScreenWidth, 220 * FitHeight) imageUrls:nil timeInterval:3 didSelect:^(NSInteger atIndex) {
        
    } didScroll:^(NSInteger toIndex) {
        
    }];
    _cycleView.backgroundColor = [UIColor whiteColor];
    _cycleView.shouldAutoClipImageToViewSize = NO;
    _cycleView.imageContentMode = UIViewContentModeScaleAspectFill;
    _cycleView.alignment = kPageControlAlignRight;
    [_cycleView setTag:1240];
    [self.headerView addSubview:_cycleView];
//    UIImageView *coverImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 210)];
//    [self.headerView addSubview:coverImageView];
//    coverImageView.image = [UIImage imageNamed:@"home_cover_placeholder"];
//    coverImageView.userInteractionEnabled = YES;
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapCoverImageView:)];
//    [coverImageView addGestureRecognizer:tap];
//    [coverImageView setTag:1240];
//    
//    self.scoreView = [[DYJMovieScoreView alloc] init];
//    self.scoreView.frame = CGRectMake(coverImageView.frame.size.width - 90, 120, 120, 100);
//    _scoreView.scoreLabel.text = _movie_score;
//    [coverImageView addSubview:_scoreView];

//    UIButton *ticketBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [ticketBtn setImage:[UIImage imageNamed:@"movie_ticket_normal"] forState:UIControlStateNormal];
//    ticketBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 21);
//    [ticketBtn setTitle:@"购票" forState:UIControlStateNormal];
//    ticketBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
//    [ticketBtn setTitleColor:[UIColor colorWithRed:0.74 green:0.74 blue:0.74 alpha:1.00] forState:UIControlStateNormal];
//    ticketBtn.titleLabel.font = [UIFont systemFontOfSize:11];
//    [_headerView addSubview:ticketBtn];
//    [ticketBtn makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.headerView).offset(0);
//        make.top.equalTo(self.cycleView.bottom).offset(0);
//        make.height.equalTo(44);
//        make.width.equalTo(100);
//    }];
    
    UIButton *moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [moreBtn setImage:[UIImage imageNamed:@"share_image"] forState:UIControlStateNormal];
    moreBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -20);
    [moreBtn setTitle:@"分享" forState:UIControlStateNormal];
    moreBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -10, 0,-15);
    [moreBtn setTitleColor:[UIColor colorWithRed:0.74 green:0.74 blue:0.74 alpha:1.00] forState:UIControlStateNormal];
    moreBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [_headerView addSubview:moreBtn];
    [moreBtn makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.headerView).offset(0);
        make.top.equalTo(self.cycleView.bottom).offset(0);
        make.height.equalTo(44);
        make.width.equalTo(90);
    }];
    [moreBtn addTarget:self action:@selector(didClickedMoreButton:) forControlEvents:UIControlEventTouchUpInside];
    [moreBtn setTag:1252];
    
#pragma mark -- button
    _scoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_scoreBtn setImage:[UIImage imageNamed:@"not_score_normal"] forState:UIControlStateNormal];
    _scoreBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    [_scoreBtn setTitle:@"评分" forState:UIControlStateNormal];
    _scoreBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
    [_scoreBtn setTitleColor:[UIColor colorWithRed:0.74 green:0.74 blue:0.74 alpha:1.00] forState:UIControlStateNormal];
    _scoreBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [_scoreBtn addTarget:self action:@selector(didClickedScoreButton:) forControlEvents:UIControlEventTouchUpInside];
    [_headerView addSubview:_scoreBtn];
    [_scoreBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView).offset(5);
        make.top.equalTo(self.cycleView.bottom).offset(0);
        make.height.equalTo(44);
        make.width.equalTo(90);
    }];
    
    _scoreLabel = [[UILabel alloc] init];
    _scoreLabel.textColor = [UIColor colorWithRed:0.52 green:0.67 blue:0.84 alpha:1.00];
    _scoreLabel.font = [UIFont systemFontOfSize:14];
    [_headerView addSubview:_scoreLabel];
    [_scoreLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView).offset(8);
        make.top.equalTo(self.cycleView.bottom).offset(0);
        make.height.equalTo(44);
        make.width.equalTo(100);
    }];
    if ([[NSUserDefaults standardUserDefaults] integerForKey:[NSString stringWithFormat:@"score_%@",self.movie_id]]) {
        _scoreLabel.text = [NSString stringWithFormat:@"%ld 我的评分",(long)[[NSUserDefaults standardUserDefaults] integerForKey:[NSString stringWithFormat:@"score_%@",self.movie_id]]];
        _scoreBtn.hidden = YES;
    }else {
        _scoreLabel.text = [NSString stringWithFormat:@"100 我的评分"];
        _scoreLabel.hidden = YES;
    }
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor colorWithRed:0.74 green:0.74 blue:0.74 alpha:0.3];
    [_headerView addSubview:lineView];
    [lineView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView);
        make.top.equalTo(moreBtn.bottom).offset(0);
        make.height.equalTo(1);
        make.width.equalTo(ScreenWidth);
    }];
    
    self.storyView = [[XZHMovieStoryView alloc] initWithMovie_id:_movie_id];
//    self.storyView.backgroundColor = [UIColor greenColor];
    DXYWeakSelf
    _storyView.StoryBlock = ^(CGFloat storyViewHeight) {
        
        weakSelf.headerView.frame = CGRectMake(0, 0, ScreenWidth,  storyViewHeight + 380);
        
        [weakSelf.storyView makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView.bottom).offset(3);
            make.left.equalTo(weakSelf.headerView);
            make.height.equalTo(storyViewHeight + 80);
            make.width.equalTo(ScreenWidth);
        }];
        [weakSelf.tableView setTableHeaderView:weakSelf.headerView];
        [weakSelf.tableView endUpdates];
        [weakSelf.hourGlass removeFromSuperview];
    };
    [_headerView addSubview:_storyView];
    [self.tableView reloadData];
    
    UILabel *movieCommentLabel = [[UILabel alloc] init];
    movieCommentLabel.text = @"评论列表";
    movieCommentLabel.font = [UIFont systemFontOfSize:12];
    movieCommentLabel.textColor = [UIColor colorWithRed:0.62 green:0.62 blue:0.62 alpha:1.00];
    [self.headerView addSubview:movieCommentLabel];
    [movieCommentLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView).offset(10);
        make.top.equalTo(self.storyView.bottom).offset(5);
        make.width.equalTo(100);
        make.height.equalTo(30);
    }];

}

- (void)setUpTableViewFooterView {
    self.footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 150)];
//    self.footerView.backgroundColor = [UIColor redColor];
    self.tableView.tableFooterView = _footerView;
    
    UIButton *allCommentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [allCommentBtn setTitleColor:[UIColor colorWithRed:0.62 green:0.78 blue:0.91 alpha:1.00] forState:UIControlStateNormal];
    [allCommentBtn setTitle:@"全部评论" forState:UIControlStateNormal];
    allCommentBtn.titleLabel.font = [UIFont systemFontOfSize:11];
    [allCommentBtn addTarget:self action:@selector(didClickedAllCommentButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.footerView addSubview:allCommentBtn];
    [allCommentBtn makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.footerView);
        make.top.equalTo(self.footerView).offset(-30);
        make.width.equalTo(75);
        make.height.equalTo(25);
    }];
    
    self.formView = [[XZHMovieFormView alloc] init];
    [self.footerView addSubview:_formView];
    [_formView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(allCommentBtn.bottom).offset(10);
        make.left.equalTo(self.footerView);
        make.width.equalTo(ScreenWidth);
        make.height.equalTo(140);
    }];
    
//    self.scaleView = [[XZHMovieScaleView alloc] init];
//    [self.footerView addSubview:_scaleView];
//    DXYWeakSelf
//    _scaleView.ScaleBlock = ^(CGFloat scaleViewHeight) {
//        
//        weakSelf.footerView.frame = CGRectMake(0, 0, ScreenWidth,  scaleViewHeight + 200);
//        
//        [weakSelf.scaleView makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(weakSelf.footerView);
//            make.top.equalTo(weakSelf.formView.bottom).offset(5);
//            make.width.equalTo(ScreenHeight);
//            make.height.equalTo(scaleViewHeight);
//        }];
//        [weakSelf.tableView setTableFooterView:weakSelf.footerView];
//        [weakSelf.tableView endUpdates];
//    };
//    
}

- (void)myTask
{
    // Do something usefull in here instead of sleeping ...
    sleep(6);
}

- (void)getMovieDetailDataByUrl {
    
    
    NSString *url = [NSString stringWithFormat:@"http://v3.wufazhuce.com:8000/api/movie/detail/%@?platform=ios&uuid=5DA53470-1598-42FF-AB78-E2812C9D28AE&user_id=&version=v4.2.1&source=channel_movie&source_id=11583", _movie_id];
    [ZHNetworkHandler getDataByURLString:url WithBodyString:nil WithHeaderDic:nil WithResponse:0 WithSuccess:^(id result) {
        _model = [[XZHMovieDetailModel alloc] initWithDic:[(NSDictionary *)result objectForKey:@"data"]];
        
        _formView.model = _model;
        _scaleView.model = _model;
        
//        [(UIImageView *)[self.headerView viewWithTag:1240] sd_setImageWithURL:[NSURL URLWithString:_model.detailcover]];
        [(HYBLoopScrollView *)[self.headerView viewWithTag:1240] setImageUrls:_model.photo];

        [self.tableView reloadData];
        
    } WithFailure:^(NSError *error) {
        
    }];
}

- (void)getMovieCommentDataByUrl {
    NSString *url = [NSString stringWithFormat:@"http://v3.wufazhuce.com:8000/api/comment/praise/movie/%@/0", _movie_id];
    [ZHNetworkHandler getDataByURLString:url WithBodyString:nil WithHeaderDic:nil WithResponse:0 WithSuccess:^(id result) {
        self.commentDataSource = [NSMutableArray array];
        
        NSArray *array = [[(NSDictionary *)result objectForKey:@"data"] objectForKey:@"data"];
        if (array.count >= 5) {
            for (NSInteger i = 0; i < 5; i++) {
                NSDictionary *dic = [array objectAtIndex:i];
                XZHMovieCommentModel *model = [[XZHMovieCommentModel alloc] initWithDic:dic];
                [self.commentDataSource addObject:model];
            }
        }
        [self.tableView reloadData];
    } WithFailure:^(NSError *error) {
        
    }];
}


#pragma mark 评分按钮点击事件
- (void)didClickedScoreButton:(UIButton *)sender {

    [self.view bringSubviewToFront:_giveScoreView];
    self.navigationController.navigationBar.hidden = YES;
    self.giveScoreView.hidden = NO;
}

-(void)newValue:(TBCircularSlider*)slider{
    //TBCircularSlider *slider = (TBCircularSlider*)sender;
    slider.score = [NSString stringWithFormat:@"%d",slider.angle * 100 / 360];
    switch (slider.angle * 100 / 360 / 10) {
        case 0:
            _rankLabel.text = @"太差劲";
            break;
        case 1:
            _rankLabel.text = @"不可思议";
            break;
        case 2:
            _rankLabel.text = @"竟然会这样";
            break;
        case 3:
            _rankLabel.text = @"呵呵了";
            break;
        case 4:
            _rankLabel.text = @"什么东西啊";
            break;
        case 5:
            _rankLabel.text = @"一般般";
            break;
        case 6:
            _rankLabel.text = @"凑合看吧";
            break;
        case 7:
            _rankLabel.text = @"还行";
            break;
        case 8:
            _rankLabel.text = @"挺棒啦";
            break;
        case 9:
            _rankLabel.text = @"必看";
            break;
        case 10:
            _rankLabel.text = @"完美";
            break;
        default:
            _rankLabel.text = @"完美";
            break;
    }
}
#pragma mark -- 创建评分底部视图
- (void)createGiveScoreView
{
    //分数底部view
    _giveScoreView = [[UIView alloc] initWithFrame:self.view.frame];
//    _giveScoreView.backgroundColor = [UIColor colorWithRed:0.52 green:0.67 blue:0.84 alpha:1.00];
    [self.view addSubview:_giveScoreView];
    _giveScoreView.hidden = YES;
    
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.backgroundColor = [UIColor colorWithRed:0.80 green:0.83 blue:0.86 alpha:0.5];
    effectView.frame = self.view.frame;
    [_giveScoreView addSubview:effectView];
    //添加点击手势
    UITapGestureRecognizer *tapScoreView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapScoreView)];
    [_giveScoreView addGestureRecognizer:tapScoreView];
    //添加完成按钮
    UIImageView *finishImageView = [[UIImageView alloc] initWithFrame:CGRectMake((ScreenWidth - 36) / 2, 460 * FitHeight, 40, 40)];
    finishImageView.image = [UIImage imageNamed:@"complete"];
    //添加点击手势
    finishImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapFinishImageView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapFinishImageView)];
    [finishImageView addGestureRecognizer:tapFinishImageView];
    [self.giveScoreView addSubview:finishImageView];
    
    UILabel *finishLabel = [[UILabel alloc] initWithFrame:CGRectMake(finishImageView.frame.origin.x, finishImageView.frame.origin.y + finishImageView.frame.size.height, finishImageView.frame.size.width, finishImageView.frame.size.height)];
    finishLabel.textAlignment = 1;
    finishLabel.textColor = [UIColor whiteColor];
    finishLabel.text = @"完成";
    finishLabel.font = [UIFont systemFontOfSize:13];
    [self.giveScoreView addSubview:finishLabel];
    
    //评价等级label
    _rankLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 80 * FitHeight, ScreenWidth, 40)];
    _rankLabel.textAlignment = 1;
    _rankLabel.textColor = [UIColor whiteColor];
    //_rankLabel.font = [UIFont systemFontOfSize:13];
    [_giveScoreView addSubview:_rankLabel];
   // [self.giveScoreView bringSubviewToFront:finishImageView];
    _giveScoreView.frame = CGRectMake(0, -64, ScreenWidth, ScreenHeight );
    //Create the Circular Slider
    _slider = [[TBCircularSlider alloc]initWithFrame:CGRectMake((ScreenWidth - TB_SLIDER_SIZE) / 2.0, 110 * FitHeight, TB_SLIDER_SIZE, TB_SLIDER_SIZE)];
    _slider.score = [NSString stringWithFormat:@"100"];
    //Define Target-Action behaviour
    [_slider addTarget:self action:@selector(newValue:) forControlEvents:UIControlEventValueChanged];
    
    [self.giveScoreView addSubview:_slider];

}
- (void)didTapScoreView
{
    self.navigationController.navigationBar.hidden = NO;
    _scoreLabel.hidden = YES;
    _giveScoreView.hidden = YES;
    
}
- (void)didTapFinishImageView
{
    _scoreLabel.hidden = NO;
    if (![_slider.score isEqualToString:@"100"]) {
        _scoreLabel.text = [NSString stringWithFormat:@"%@ 我的评分", _slider.score];
        [[NSUserDefaults standardUserDefaults] setInteger:[_slider.score integerValue] forKey:[NSString stringWithFormat:@"score_%@",self.movie_id]];
    } else {
        [[NSUserDefaults standardUserDefaults] setInteger:100 forKey:[NSString stringWithFormat:@"score_%@",self.movie_id]];
        _scoreLabel.text = [NSString stringWithFormat:@"100 我的评分"];
    }
    
    self.navigationController.navigationBar.hidden = NO;
    _scoreBtn.hidden = YES;
    _giveScoreView.hidden = YES;
    _scoreLabel.hidden = NO;
}

- (void)didClickedMoreButton:(UIButton *)sender{
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:[NSString stringWithFormat:@"最近新上映了[%@],约吗?",_model.title]
                                     images:_model.detailcover
                                        url:[NSURL URLWithString:@"http://www.jianshu.com/users/8763aac98cf7/latest_articles"]
                                      title:@"PIECE"
                                       type:SSDKContentTypeAuto];
    
    
    //调用自定义分享
    [JZShareCustom shareWithContent:shareParams Url:_model.video  Title:nil Type:nil HomeModel:nil MovieModel:_model];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.commentDataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    UITableViewCell *cell = [[UITableViewCell alloc] init];
    XZHMovieCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commentCell"];
    cell.model = [self.commentDataSource objectAtIndex:indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    XZHMovieCommentModel *model = [self.commentDataSource objectAtIndex:indexPath.row];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:12], NSFontAttributeName,nil];
    CGRect newRect = [model.content boundingRectWithSize:CGSizeMake(ScreenWidth - 63, 8000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    NSLog(@"%f", newRect.size.height);
    return newRect.size.height + 100;
}

- (void)didClickedAllCommentButton:(UIButton *)sender {
    XZHMovieCommentViewController *commentVC = [[XZHMovieCommentViewController alloc] init];
    [self.navigationController pushViewController:commentVC animated:YES];
}




- (void)didTapCoverImageView:(UITapGestureRecognizer *)tap {
    videoPlayerController = [[HDVideoPlayerController alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 210)];
    
    [self.view addSubview:videoPlayerController.view];
    [videoPlayerController.view setTag:1260];
    videoPlayerController.videoControl.delegate = self;
    
//    UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [closeButton setBackgroundImage:[UIImage imageNamed:@"video-player-close"] forState:UIControlStateNormal];
//    [videoPlayerController.view addSubview:closeButton];
//    [closeButton makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(videoPlayerController.view).offset(10);
//        make.right.equalTo(videoPlayerController.view).offset(-10);
//        make.height.equalTo(20);
//        make.width.equalTo(20);
//    }];
//    [closeButton addTarget:self action:@selector(didClickedCloseButton:) forControlEvents:UIControlEventTouchUpInside];
  
  
    //设置视频地址
    videoPlayerController.contentURL = [NSURL URLWithString:_model.video];
//    [[videoPlayerController movieBackgroundView] sd_setImageWithURL:[NSURL URLWithString:_model.web_url]];
#pragma mark -- 音乐暂停
    AudioPlayerManager *playerManager = [AudioPlayerManager shareAudioPlayerManager];
    //playerManager.delegate = self;
    [playerManager pause];
    [[XZHMusicPlayView shareMusicPlayViewInstance] setIsPlay:NO];
    [[[XZHMusicPlayView shareMusicPlayViewInstance] pauseButton] setHidden:YES];
    [[[XZHMusicPlayView shareMusicPlayViewInstance] playButton] setHidden:NO];
        
    [videoPlayerController play];
    DXYWeakSelf;
    //开启全屏回调事件
    videoPlayerController.fullScreenBlock = ^(){
        
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
        [weakSelf.navigationController setNavigationBarHidden:YES animated:NO];
        weakSelf.tabBarController.tabBar.hidden = YES;
        
    };
    //关闭全屏回调事件
    videoPlayerController.shrinkScreenBlock = ^(){
        [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
        [weakSelf.navigationController setNavigationBarHidden:NO animated:NO];
        weakSelf.tabBarController.tabBar.hidden = NO;
    };
}

//- (void)didClickedCloseButton:(UIButton *)sender {
//    [[self.view viewWithTag:1260] removeFromSuperview];
//    [videoPlayerController close];
//    videoPlayerController = nil;
//}

- (void)closePlayView {
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    [[self.view viewWithTag:1260] removeFromSuperview];
        [videoPlayerController close];
        videoPlayerController = nil;
    [self.navigationController setNavigationBarHidden:NO animated:NO];

}

- (void)viewWillAppear:(BOOL)animated
{
    _hourGlass = [[FeHourGlass alloc] initWithView:self.tableView];
    [self.view addSubview:_hourGlass];
    [_hourGlass showWhileExecutingBlock:^{
        [self myTask];
    } completion:^{
        
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidDisappear:(BOOL)animated {
    [videoPlayerController close];
    videoPlayerController = nil;
    [self.cycleView pauseTimer];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
